#include <bits/stdc++.h>
using namespace std;
int t,d[100001],u[100001],a[100001],p[100001];
int main(){
    freopen("detest.in","r",stdin);
    freopen("detest.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        int n,m,l,v;
        scanf("%d%d%d%d",&n,&m,&l,&v);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&u[i],&a[i]);
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
        }
        sort(p+1,p+m+1);
        int ans = 0;
        for(int i=1;i<=n;i++){
            if(d[i] <= p[n]){
                if(u[i] > v){
                    ans++;
                }
            }
        }
        printf("%d ",ans);
        if(ans != 0){
            printf("%d\n",m-1);
        }else{
            printf("%d\n",m);
        }
    }
    return 0;
}

